import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
import { ManageService } from './manage.service';
import { CreateManageDto } from './dto/create-manage.dto';
import { UpdateManageDto } from './dto/update-manage.dto';
import { GlobalService } from '../global/global.service'
// @Controller('manage') // 访问 /manage
@Controller({
  path: 'manage',
  version: '1', // 版本控制，需要访问前缀 /v1/manage
})
export class ManageController {
  constructor(private readonly manageService: ManageService, private readonly globalService: GlobalService) { }

  /** 
   * post请求，访问 /manage时候如果是post请求，则执行create方法
   *  @Body() createManageDto: CreateManageDto，表示获取请求体中的数据，并赋值给createManageDto
   *  */

  @Post()
  create(@Body() createManageDto: CreateManageDto) {
    return this.manageService.create(createManageDto);
  }

  /**
   * get请求，访问 /manage时候如果是get请求，则执行findAll方法
   * 
   */
  @Get()
  findAll() {

    return this.manageService.findAll() + this.globalService.findAll();
  }

  /**
   * /manage/:id
   * @param id 获取url中的id参数
   */
  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.manageService.findOne(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateManageDto: UpdateManageDto) {
    return this.manageService.update(+id, updateManageDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.manageService.remove(+id);
  }
}
